home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.5 KB | 299 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWContnt.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCONTNT_H
- #include "FWContnt.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRMISE_H
- #include "FWPrmise.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWSUUTIL_H
- #include "FWSUUtil.h"
- #endif
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkContent
- #endif
-
- //========================================================================================
- // class FW_CContent
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_CContent)
-
- //----------------------------------------------------------------------------------------
- // FW_CContent constructor
- //----------------------------------------------------------------------------------------
-
- FW_CContent::FW_CContent(Environment* ev, FW_CPart* part) :
- fPart(part)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent destructor
- //----------------------------------------------------------------------------------------
-
- FW_CContent::~FW_CContent()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::AcquireSuggestedFrameShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CContent::AcquireSuggestedFrameShape(Environment* ev)
- {
- FW_UNUSED(ev);
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::ReleaseAll
- //----------------------------------------------------------------------------------------
-
- void FW_CContent::ReleaseAll(Environment* ev)
- {
- FW_UNUSED(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::NewPromise
- //----------------------------------------------------------------------------------------
-
- FW_CPromise* FW_CContent::NewPromise(Environment* ev, ODStorageUnit* su, FW_StorageKinds storageKind, FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(su);
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_DeletePromiseIfZeroCount
- //----------------------------------------------------------------------------------------
-
- static void FW_DeletePromiseIfZeroCount(Environment* ev, FW_CPromise* promise)
- {
- if (promise && (promise->GetCount(ev) == 0))
- {
- if (promise->GetStorageKind(ev) == FW_kLinkStorage)
- promise->PrivGetLinkSource(ev)->SetLinkPromise(ev, NULL);
- else
- delete promise;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::Externalize
- //----------------------------------------------------------------------------------------
-
- void FW_CContent::Externalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_CPromise* promise = NULL;
-
- // ----- Try to create a promise ------
- if (storageKind != FW_kPartStorage) // can't promise for Part storage
- promise = NewPromise(ev, storageUnit, storageKind, cloneInfo);
-
- FW_TRY
- {
- // Go through all the values and externalize them one by one
- this->PrivExternalizeAllValues(ev, storageUnit, storageKind, promise, cloneInfo);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- FW_DeletePromiseIfZeroCount(ev, promise);
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- FW_DeletePromiseIfZeroCount(ev, promise);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CContent::PrivExternalizeAllValues
- //---------------------------------------------------------------------------------------
- // Private method called from FW_CPart::ExternalizeKinds and FW_CContent::Externalize
-
- void FW_CContent::PrivExternalizeAllValues(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- // ----- Now I can call FW_CContent::ExternalizeKind on each existing value
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, 0, kODPosAll);
-
- unsigned long numValues = storageUnit->CountValues(ev);
- for (unsigned long index = 1; index <= numValues ; index++)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, NULL, index, kODPosUndefined);
- FW_CAcquireODISOStr valueType = storageUnit->GetType(ev);
- FW_CKind* kind = fPart->GetKind(ev, valueType);
-
- if (kind && kind->IsDirty(ev, storageKind))
- {
- ExternalizeKind(ev, storageUnit, kind, storageKind, promise, cloneInfo);
- kind->PrivSetDirty(ev, FALSE, storageKind);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::ExternalizeKind
- //----------------------------------------------------------------------------------------
-
- void FW_CContent::ExternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CPromise* promise,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(storageUnit);
- FW_UNUSED(kind);
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
- FW_UNUSED(promise);
-
- FW_DEBUG_MESSAGE("You need to override FW_CContent::ExternalizeKind");
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::Internalize
- //----------------------------------------------------------------------------------------
- // Override InternalizeKind
-
- FW_Boolean FW_CContent::Internalize(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_Boolean done = FALSE;
- FW_Boolean result = FALSE;
-
- // ----- Look first for a file (part storage only) -----
- #ifdef FW_BUILD_MAC
- if (storageKind == FW_kPartStorage)
- {
- HFSFlavor valueData;
- if (FW_MacSUReadHFSFlavor(ev, storageUnit, kODPropContents, valueData))
- {
- FW_CPartKindIterator ite(fPart);
- for (FW_CKind* kind = ite.First(); ite.IsNotComplete(); kind = ite.Next())
- {
- if (kind->ImportSupported(ev, storageKind))
- {
- if (kind->IsEqual(ev, valueData.fileType, kODPlatformFileType))
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kind->GetType(ev), 0, kODPosUndefined);
- result = InternalizeKind(ev, storageUnit, kind, storageKind, cloneInfo);
- done = TRUE;
- break;
- }
- }
- }
- }
- }
- #endif
-
- if (!done)
- {
- FW_CKind* theKind = NULL;
-
- // ----- if part storage use the preferred kind. For other storage use the highest supported fidelity
- if (storageKind == FW_kPartStorage)
- {
- theKind = fPart->GetPreferredKind(ev);
- FW_ASSERT(theKind != NULL); // Otherwise why was I bound to this part?
- FW_ASSERT(storageUnit->Exists(ev, kODPropContents, theKind->GetType(ev), 0)); // and it better exists
- }
- else
- theKind = fPart->GetSupportedKind(ev, storageUnit, storageKind);
-
- if (theKind != NULL)
- {
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, theKind->GetType(ev), 0, kODPosUndefined);
- result = InternalizeKind(ev, storageUnit, theKind, storageKind, cloneInfo);
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CContent::InternalizeKind
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CContent::InternalizeKind(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CKind* kind,
- FW_StorageKinds storageKind,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(storageUnit);
- FW_UNUSED(kind);
- FW_UNUSED(storageKind);
- FW_UNUSED(cloneInfo);
-
- FW_DEBUG_MESSAGE("You need to override FW_CContent::InternalizeKind");
- return FALSE;
- }
-